import { Navigate } from "react-router-dom";
import { getToken } from "@/utils/token";
import PropTypes from "prop-types";

// 路由鉴权 高阶组件
const AuthTokenComponent = ({ children }) => {
  const isToken = getToken();
  return isToken ? children : <Navigate to="/login" replace />;
};
// 对 auth 进行类型检查
AuthTokenComponent.propTypes = {
  children: PropTypes.node.isRequired,
};

export default AuthTokenComponent;
